package Client;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.InetAddress;
import java.net.Socket;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;

public class Client {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		 DataOutputStream ous =null;
		 DataInputStream ins = null; 

		try {
			// Construct data
			String data = URLEncoder.encode("key1", "UTF-8") + "="
					+ URLEncoder.encode("value1", "UTF-8");
			data += "&" + URLEncoder.encode("key2", "UTF-8") + "="
					+ URLEncoder.encode("value2", "UTF-8");

			// Create a socket to the host
			String hostname = "localhost";
			int port = 5555;
			InetAddress addr = InetAddress.getByName(hostname);
			Socket socket = new Socket(addr, port);

			// Send header
			String path = "/index.html";
			
		    ous = new DataOutputStream(socket.getOutputStream());
		    ins = new DataInputStream(socket.getInputStream());
		    
			
			ous.writeBytes("POST " + path + " HTTP/1.0\r\n");
			ous.writeBytes("Content-Length: " + data.length() + "\r\n");
			ous.writeBytes("Content-Type: application/x-www-form-urlencoded\r\n");
			ous.writeBytes("\r\n");

			// Send data
			ous.writeBytes(data);
			ous.flush();
			
			System.out.println("data :"+data);
			System.out.println("data length:"+data.length());

			// Get response
		
		} catch (Exception e) {
		}

	}
}
